package com.haiheng.module_main.mode

import androidx.lifecycle.MutableLiveData
import com.haiheng.common.bean.UserInfoBean
import com.haiheng.common.utils.DatabaseHelper
import com.haiheng.library.log.LogUtils
import com.haiheng.library_base.model.BaseViewModel

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2022/5/12 0012
 * @Version: 1.0
 */
class UserViewModel : BaseViewModel() {

    val userInfoBean = MutableLiveData<UserInfoBean>()

    fun getUserPatronSn(): String{
        var pat = userInfoBean.value?.patronSn ?: ""
        LogUtils.e("执行 getUserPatronSn patronSn "+pat+" _result:"+userInfoBean?.value?.toJson())
        return pat
    }

    fun getUserBean(): UserInfoBean{
        return userInfoBean.value?: UserInfoBean()
    }

    fun updateUserBean(userBean: UserInfoBean) {
        DatabaseHelper.setUser(userBean)
        userInfoBean.postValue(userBean)
    }

    fun getUser(){
        DatabaseHelper.getUser {
            userInfoBean.postValue(it)
        }
    }

}